package ua.kpi.apolonov.normalizers;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import ua.kpi.apolonov.answers.Answer;
import ua.kpi.apolonov.answers.FalseAnswer;
import ua.kpi.apolonov.answers.TrueAnswer;
import ua.kpi.apolonov.questions.FileQuestionStructure;

/**
 * Here contain methods for normalisation  for normalisation different data in correct types of answers
 * @version
 * @author Yegor Apolonov
 */

public class AnswersNormalizers implements Serializable {
	
	private String[] detailsOfQuestion = null;
	
	public AnswersNormalizers() {}
		
	public AnswersNormalizers(String[] detailsOfQuestion) {
		this.detailsOfQuestion = detailsOfQuestion;
	}
	
	public int numberNormalizer(int number) {
		return number - 1;
	}
	
	public String[] textElementsNormalizer(String[] textElements) {
		Arrays.sort(textElements);
		return textElements;
	}
	
	public List<Answer> NumericAnswerNormalizer(FileQuestionStructure questionStructure) {
		
		int offsetToAnswers = questionStructure.getOffsetToAnswers();
		int lastTrueAnswerPosition = questionStructure.getOffsetToAnswers() + questionStructure.getTrueAnswersNumber();
		List<Answer> answer = new ArrayList<Answer>();
		for(String textOfAnswer : Arrays.copyOfRange(detailsOfQuestion, offsetToAnswers, lastTrueAnswerPosition)) {
             answer.add(new TrueAnswer(textOfAnswer));
        }
        for(String textOfAnswer : Arrays.copyOfRange(detailsOfQuestion, lastTrueAnswerPosition, detailsOfQuestion.length)) {
        	answer.add(new FalseAnswer(textOfAnswer));
        }
        return answer;
    }
	
	public List<Answer> YesNoAnswerNormalizer(FileQuestionStructure questionStructure) {
		List<Answer> answer = new ArrayList<Answer>();
		answer.add(new TrueAnswer(detailsOfQuestion[2])); 	
		answer.add(new FalseAnswer(detailsOfQuestion[3]));
		return new ArrayList<Answer>(answer);
	}
	
	public List<Answer> DefaultNormalizer(FileQuestionStructure questionStructure) {
		List<Answer> answer = new ArrayList<Answer>();
		answer.add(new TrueAnswer(detailsOfQuestion[2])); 	
		return new ArrayList<Answer>(answer);
	}
}
